/*
 * --------------------------------------------------------------
 * Copyright ©  2015 Hangzhou DtDream Technologies Co.,Ltd.
 * --------------------------------------------------------------
 *      Product: 协同数治
 *  Module Name: design
 * Date Created: 2022/12/16
 *  Description: TODO
 * --------------------------------------------------------------
 * Modification History
 * DATE            NAME            Description
 * --------------------------------------------------------------
 * 2022/12/16       yewj            TODO
 * --------------------------------------------------------------
 */

package com.dtdream.pattern.single.type3;

/**
 * 懒汉式-线程不安全
 *
 * @Author: yewj
 **/
public class SingleThree {
    public static void main(String[] args) {

        Singleton instanceOne = Singleton.getInstance();
        Singleton instanceTwo = Singleton.getInstance();
        System.out.println(instanceOne == instanceTwo);
        System.out.println("instanceOne.hashCode() = " + instanceOne.hashCode());
        System.out.println("instanceTwo.hashCode() = " + instanceTwo.hashCode());
    }
}

class Singleton {
    private static Singleton instance;

    private Singleton() {}

    // 提供一个静态的公有方法，当使用到该方法时，才去创建instance
    public static Singleton getInstance() {
        if (instance == null) {
            instance = new Singleton();
        }
        return instance;
    }
}
